const { execSQL } = require("../db/mysql")

const getList = (author, keyword) => {
    let sql = `select * from blog where 1=1 `

    //从数据库里面拿
    if (author) {
        sql += `and author='${author}' `
    }
    if (keyword) {
        sql += `and title like '%${keyword}%' `
    }
    return execSQL(sql)
}
const getDetail = (id) => {
    return {
        id: 1,
        title: '标题1',
        author: 'songsikai',
        creatAt: 1645664545
    }
}

const createUser = (name, pwd) => {
    console.log('*****', name, pwd)
    let sql = `insert into user(name,pwd) values('${name}','${pwd}')`
    console.log('sql', sql)
    return execSQL(sql).then(v => {
        return { id: v.insertId }
    })

}
module.exports = {
    getList,
    getDetail,
    createUser
}